<style lang="less">
@import '../../../assets/style/renyuanxuanze.less';
.pop_up{
	.van-popup {
		width: 85%;
		padding: 10px;
		max-height: 80%;
		min-height: 18%;
		text-align: left;
		.list_box{
			font-size:14px;
			border-bottom:1px dotted #ddd;
			.title {
				display: inline-block;
				width: 30%;
			}
		}
	}
}
</style>

<template>
	<mxq-router-layout>
		<div class="search towerList">
			<Head slot="header" @headerClick="headerClick($event)">
				<div slot="headerTitle">
					<van-search v-model.trim="value" placeholder="请输入杆塔名称" @input="onSearch"/>
				</div>
				<div slot="headerRight">
					<i class="iconfont icon-shouye"/>
					<!-- <van-icon class="home" name="home"/> -->
				</div>
			</Head>
			<ganta-List
				:gantaList="gtLists"
				:picUrlLeft="picUrlLeft"
				@clickList="clickList">
				<template slot="titles1" slot-scope="item">
					<span class="iconBox">
						<img
							:src="picUrlRight"
							alt=""
							class="iconRight">
						<em class="iconText">{{iconText}}</em>
					</span>
				</template>
			</ganta-List>
			<div class="tower_text" v-show="isShow" v-if="gtLists.length==0">
				没有找到"{{value}}"的搜索结果
			</div>
			<!-- 隐 -->
			<div class="pop_up">
				<van-popup v-model="yin">
					<div>
						<div v-for="(item,index) in hiddenData" :key="index" class="list_box">
							<p>
								<span class="title">分类：</span>
								<span class="name">{{item.NAME}} ({{item.TYPE ? '隐' : "1"}})</span>
							</p>
							<p>
								<span class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span  class="title">责任人：</span>
								<span class="name">{{true?item.USERNAME:''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>

			<!-- 缺陷 -->
			<div class="pop_up">
				<van-popup v-model="que">
					<span class="pop_txt" style="font-size:16px;">
						缺陷
					</span>
					<div>
						<div v-for="(item,index) in defectsData" :key="index" class="list_box">
							<p>
								<span  class="title">分类：</span>
								<span class="name">{{item.NAME}} ({{item.TYPE ? '缺' : "0"}})</span>
							</p>
							<p>
								<span  class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span class="title">责任人：</span>
								<span class="name">{{true?item.USERNAME:''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>

			<div class="pop_up">
				<van-popup v-model="yinAndQue">
					<div class="con_box">
						<div v-for="(item,index) in hiddenDefectsData" :key="index" class="list_box">
							<p>
								<span class="title">分类：</span>
								<span class="name" v-if="item.TYPE=='0'">{{item.NAME}} ({{item.TYPE ? '缺' : "0"}})</span>
								<span class="name" v-else>{{item.NAME}} ({{item.TYPE ? '隐' : "1"}})</span>
							</p>
							<p>
								<span class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span class="title">责任人：</span>
								<span class="name">{{true?item.USERNAME:''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>
		</div>
	</mxq-router-layout>
</template>

<script>
import Head from '../../../components/head'
import GantaList from '../../../components/ganta-list'
import IconGT from '../../../assets/img/changguixunshi/icon_gt.png'
import IconQD from '../../../assets/img/changguixunshi/icon_rw.png'
import { callData } from '../../../axios/axios'
import { getSession } from '../../../libs/cache'

import {
	Icon,
	Search,
	Popup,
	Toast
} from 'vant'

export default {
	name:'gantaxunshi',
    components: {
		Head,
		GantaList,
		[Icon.name]: Icon,
		[Search.name]: Search,
		[Popup.name]: Popup,
		[Toast.name]: Toast
	},
	data() {
		return {
			cname: 'iconRight',			//列表右侧图标类名
			iconText: '接受任务',	 	//右侧按钮文案
			value: '',					//人员姓名
			gtLists: [],				//杆塔列表数据
			xsTowerTaskIds: [],			//巡视杆塔ID
			picUrlLeft: IconGT,			//列表左侧图片
			picUrlRight: IconQD,		//列表右侧图片(接受任务)
			yin:false,					//隐
			hiddenData: [],				//隐患数据
			listType: [],				//隐患详情Key
			detailShow: [],				//数据集合
			que:false,					//缺
			defectsData: [],			//缺陷数据
			hiddenDefectsData:[],		//隐患和缺陷数据
			yinAndQue: false,			//隐和缺
			isShow: false,				//搜索结果
			params: this.$route.query	//获取地址栏参数
		}
	},
	mounted() {
		this.getListData();
    },
    methods: {
		// 头部两侧按钮点击事件
		headerClick(e){
			this.$router.push({name:"index"})
		},
		displayShow:function(){
			var _this =this;
			_this.listType = ['发现时间','责任人','等级','状态']
		},
		// 点击列表跳转
		clickList(e){
			console.log(e);
			var userMeg = JSON.parse(getSession('userMeg'));
			let query = {
				xsId: this.params.xsId,
				xsTowerTaskId: e.data.ID,
				lineTowerId: e.data.LINE_TOWER_ID,
				taskId: e.data.TASK_ID,
				towerId: e.data.TOWER_ID,
				towerName: e.data.TOWER_NAME,
				lineId: e.data.LINE_ID,
				jdUserId: e.data.JD_USER_ID,
				lineName:e.data.LINE_NAME,
				phoType: e.data.PHOTO_TYPE,//拍照必拍项
				status: e.data.STATUS,
				taskEndTime: this.params.taskEndTime,//任务结束时间
				taskStatus:this.params.taskStatus,//任务状态
				towerStatus: 1,//杆塔状态
				needMeasure: e.data.NEED_MEASURE,//测量限制
				towerTaskId: e.data.ID,
				index: this.params.index,	//taskType任务类型
				page: this.params.page,
				size: this.params.size
			}
			if(e.todo == -1){
				var _this = this;
				var params = {};
				params.towerId = e.data.TOWER_ID;
				if(e.data.IS_YH=="1" && e.data.IS_QX=="0"){ //隐
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', params).then(res => {
						if(res.success){
							_this.yin = true;
							var resHidden = res.data;
							_this.hiddenData = resHidden;
						}
					})
				}
				else if(e.data.IS_QX=="1" && e.data.IS_YH=="0"){//缺
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', params).then(res => {
						if(res.success){
							_this.que = true;
							var resDefects = res.data;
							_this.defectsData = resDefects;
						}
					})
				}
				else if(e.data.IS_YH=="1" && e.data.IS_QX=="1"){//隐和缺
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', params).then(res => {
						if(res.success){
							_this.yinAndQue = true;
							var hiddendefects = res.data;
							_this.hiddenDefectsData = hiddendefects;
						}
					})
				}else {}
			}
			//点击右侧标签事件
			else if(e.todo == 0 && e.data.JD_USER_ID == null){ //开始接单
				var params ={};
				params.xsTowerTaskId = e.data.ID;
				params.acceptTask = 1; //1 接单
				callData('/xsTaskServer/ZcXsTowerTask/appXsTowerJd', 'put', params).then(res => {
					if(res.success){
						Toast(res.data)
						this.$router.push({
							path: '/cgxs_allowPhotos',
							query
						})
					}
					else {
						Toast(res.data);
					}
				})
			}
			//点击列表事件
			else if(e.todo == 1 && e.data.JD_USER_ID == null){//没有接单，只是查看
				//任务状态为0表示未巡视
				// if(e.data.STATUS == 0 ){
					this.$router.push({
						path: '/cgxs_noPhotos',
						query: {
							xsId: this.params.xsId,
							xsTowerTaskId: e.data.ID,
							lineTowerId: e.data.LINE_TOWER_ID,
							taskId: e.data.TASK_ID,
							towerId: e.data.TOWER_ID,
							towerName: e.data.TOWER_NAME,
							lineId: e.data.LINE_ID,
							jdUserId: e.data.JD_USER_ID,
							lineName:e.data.LINE_NAME,
							phoType: e.data.PHOTO_TYPE,//拍照必拍项
							status: e.data.STATUS,
							taskEndTime: this.params.taskEndTime,//任务结束时间
							taskStatus:this.params.taskStatus,//任务状态
							towerStatus: e.data.TOWER_TASK_STATUS,//杆塔状态
							needMeasure: e.data.NEED_MEASURE,//测量限制
							towerTaskId: e.data.ID,
							index: this.params.index,	//taskType任务类型
							page: this.params.page,
							size: this.params.size
						}
					})
				// }
				/* //任务状态为1表示进行中
				else if(e.data.STATUS == 1){
					if(e.data.JD_USER_ID == e.data.JD_USER_ID){
						this.$router.push({
							path: '/cgxs_allowPhotos',
							query
						})
					}
					else {
						this.$router.push({
							path: '/cgxs_noPhotos',
							query
						})
					}
				}
				//任务状态为2表示已完成
				else if(e.data.STATUS == 2) {
					this.$router.push({ 
						path: '/cgxs_allowPhotos',
						query
					})
				} */
			}else if(e.data.STATUS == 2) { //已完成的任务人可查看
				query.name = 'cgxs_allowPhotos'
				query.towerStatus = 2
				this.$router.push({
					name: 'cgxs_allowPhotos',
					query: query
				})
			}
			else if(e.todo == 1 && e.data.JD_USER_ID == userMeg.id){//接过单之后(进行中)，还可以点击列表进去，此时只可以进入自己的任务
				this.$router.push({ 
					path: '/cgxs_allowPhotos',
					query
				})
			}
			/* else{
				Toast('非本人不可进行操作');
			} */
			else if(e.todo==1){
				if (e.data.JD_USER_ID != userMeg.id) {
					Toast('非本人不可进行操作');
					return;
				}
			}
		},
		// 拿到杆塔的列表信息
		getListData(e) {
			var params ={}
			params.page = this.params.page;
			params.size = this.params.size;
			params.xsTaskId = this.params.xsId;
			callData('/xsTaskServer/ZcXsTowerTask/appXsTowerTasks', 'get', params).then(res => {
				console.log('初始res',res);
				this.initData(res);
			})
		},
		// 模糊搜索杆塔
		onSearch(){
			var params ={}
			params.page = this.params.page;
			params.size = this.params.size;
			params.xsTaskId = this.params.xsId;
			params.towerTaskName = this.value;
			callData('/xsTaskServer/ZcXsTowerTask/appXsTowerTasks', 'get', params).then(res => {
				if(res.success){
					console.log('模糊搜索杆塔res',res);
					this.initData(res);
					this.isShow=true;
				}
			})
		},
		initData(res){
			if (!res || !res.data || !res.data.content) {
				return;
			}
			var gtData = res.data.content;
			gtData.forEach((item,index) => {
				item.textName = item.LINE_NAME_SHORT + ' - ' + item.TOWER_NAME + '杆塔'
				item.alarm=item.IS_YH==1?'have':'';
				item.que=item.IS_QX==1?'have':'';
				// 状态判断
				if (item.STATUS == 0) {
					item.status = item.STATUS
					item.statusName = '未巡视'
					item.cname="btn_status"
				}else if (item.STATUS == 1) {
					item.statusName = '进行中'
					item.cname="btn_status1"
					if(JSON.parse(getSession('userMeg')).id != item.JD_USER_ID){
						item.cname="btn_statusgray"
					}
				}else{
					item.status = item.STATUS
					item.statusName = '已完成'
					item.cname="btn_status2"
					if(JSON.parse(getSession('userMeg')).id != item.JD_USER_ID){
						item.cname="btn_statusgray"
					}
				}
				this.xsTowerTaskIds = item.ID
				this.gtStatus = item.STATUS
			});
			this.gtLists = gtData;
		}
	}
}
</script>
